package jp.co.sharp.android.decome.aobject;

import java.util.ArrayList;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import dalvik.system.DexClassLoader;

public abstract class AHandler {
	abstract public ArrayList<AObject> next(int width, int height);

	abstract public int nextTime();

	static DexClassLoader r = null;

	public static void setRes(DexClassLoader res) {
		r = res;
	}

	protected Bitmap getBmp(String base64) {
		try {
			byte[] bytes;
			bytes = Base64.decode(base64);
			Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
			return bmp;
		} catch (Base64DecoderException e) {
			e.printStackTrace();
		}
		return null;
	}

	public void next(Canvas canvas) {
		float mWidth = canvas.getWidth();
		float mHeight = canvas.getHeight();

		ArrayList<AObject> list = next((int) mWidth, (int) mHeight);

		AObject.sortByZ(list);

		for (AObject aobject : list) {
			float z = aobject.getZ();
			float x = aobject.getX();
			float y = aobject.getY();
			x += mWidth / 2;
			y += mHeight / 2;
			aobject.draw(canvas, mWidth / 2, mHeight / 2, z);
		}
	}
}
